package com.neu.wangweili.servlet;

import com.neu.wangweili.service.W_DeptService;
import com.neu.wangweili.service.W_StuService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet(name = "CheckStuToUpdateStuServlet", urlPatterns = {"/CheckStuToUpdateStuServlet"})
public class CheckStuToUpdateStuServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String stu_id=request.getParameter("stu_id");
        System.out.println("stu_id"+stu_id);
        W_StuService WStuService =new W_StuService();
        W_DeptService WDeptService =new W_DeptService();
//        所有的系别信息
        List<Map<String,Object>>list= WDeptService.findAll();
//        该学生的信息
        Map<String,Object>map= WStuService.findById(stu_id);
        if(map!=null){
            HttpSession session=request.getSession();
            session.setAttribute("dept",list);
            session.setAttribute("item",map);
            request.getRequestDispatcher("WEB-INF/Mgr/update_stu.jsp").forward(request,response);
        }else{
            request.getRequestDispatcher("commons/fail.jsp").forward(request,response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
